﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web4Comment.Service;
using System.Collections;
using System.Collections.ObjectModel;

namespace Web4Comment.sns
{
    public partial class snsfriend : System.Web.UI.Page
    {
        SNSService service = new SNSService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((String)Session["username"] == null || (String)Session["username"] == "")
            {
                Response.Redirect("./logon.aspx");
            }
              if (! IsPostBack){
                    if (!service.isConnect(1))
                    {
                        Session["next_url"] = "/sns/snsfriend.aspx";
                        service.connect(1);
                    }
            
                    Collection<UnlessComment.Model.SnsFriend>bingdata = new Collection<UnlessComment.Model.SnsFriend>();
                    List<UnlessComment.Model.SnsFriend> l = service.getNewSNSFriends(1);
                    friendListAdd(l, bingdata);

                    this.friendDataList1.DataSource = bingdata;
                    this.friendDataList1.DataBind();

              }
            
        }

        protected void HandleAdd(object sender, EventArgs e)
        {
            Service.FriendsService.addFriends((String)Session["username"], ((LinkButton)sender).CommandArgument);
            ((LinkButton)sender).Enabled = false;
        }

        private void friendListAdd(List<UnlessComment.Model.SnsFriend> list, Collection<UnlessComment.Model.SnsFriend>bingdata)
        {
            
            for (int i = 0; i < list.Count; i++)
            {
                bingdata.Add(list[i]);
            }
            
        }
    }
}